<?php
/**
 * Created by PhpStorm.
 * User: Hanson
 * Date: 2016/10/30
 * Time: 15:25
 */

namespace App\Util\Traits;


use Carbon\Carbon;

trait TimeHuman
{

    public $time = [
        'created_at', 'updated_at', 'deleted_at'
    ];

    public function __get($property)
    {
        $property = explode('_', $property);

        if(in_array($property[0], $this->time) && $property[1] === 'time'){

            $column = $property . '_at';

            return Carbon::parse($this->$column)->diffForHumans(Carbon::now());

        }
    }
}